﻿using NHibernate;
using NHibernate.Cfg;

namespace DataControl
{
	public static class SessionManager
	{
		private static ISessionFactory sessionFactory;

		public static ISession GetSession()
		{
			try
			{
				if (sessionFactory == null)
				{
					var conf = new Configuration();

					sessionFactory = conf.Configure().BuildSessionFactory();
				}
				return sessionFactory.OpenSession();
			}
			catch (HibernateConfigException)
			{
				return null;
			}
		}

		public static void CloseFactory()
		{
			if (sessionFactory != null)
				sessionFactory.Close();
		}
	}
}